﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.IO;
using FCNS.Data;

namespace DoubleH.Utility
{
    /// <summary>
    /// PrintConfig.xaml 的交互逻辑
    /// </summary>
    public partial class PrintConfig : Window
    {
        public PrintConfig()
        {
            InitializeComponent();

            InitEvent();
        }

        DoubleH.Utility.Configuration.PrintConfig config = null;
        public void Init(DoubleH.Utility.Configuration.PrintConfig obj)
        {
            config = obj;
            if (config == null)
                return;

            foreach (string file in Directory.GetFiles(DbDefine.printDir, "*.html", SearchOption.AllDirectories))
                comboBoxMode.Items.Add(System.IO.Path.GetFileName(file));

            comboBoxMode.Text = config.FileName;
            checkBoxMode.IsChecked = config.Mode;
            integerUpDownRow.Value = config.Row;
        }

        private void InitEvent()
        {
            buttonOk.Click += (ss, ee) => { Save(); };
        }

        private void Save()
        {
            if (config != null)
            {
                config.Mode = checkBoxMode.IsChecked.Value;
                config.Row = integerUpDownRow.Value.Value;
                if (!string.IsNullOrEmpty(comboBoxMode.Text))
                    config.FileName = comboBoxMode.Text;
            }
            this.Close();
        }
    }
}